#include "statusdialog.h"
#include "ui_statusdialog.h"

#include <iostream>

#include "qads/dockmanager.h"
#include "qads/dockwidget.h"

class StatusDialogPrivate
{
public:
    StatusDialog *_this;
    Ui::CStatusDialogClass ui;
    QAds::DockManager* DockManager;
    QMap<QString, QAds::DockWidget*> DockWidgets;

    /**
     * Private data constructor
     */
    StatusDialogPrivate(StatusDialog *_public);
};
// struct StatusDialogPrivate

//============================================================================
StatusDialogPrivate::StatusDialogPrivate(StatusDialog *_public) :
    _this(_public)
{

}

//============================================================================
StatusDialog::StatusDialog(QAds::DockManager* DockManager) :
    QDialog(DockManager),
    d(new StatusDialogPrivate(this))
{
    d->ui.setupUi(this);
    d->DockManager = DockManager;
    d->DockWidgets = DockManager->dockWidgetsMap();

    for (auto it = d->DockWidgets.begin(); it != d->DockWidgets.end(); ++it)
    {
        QVariant vDockWidget = QVariant::fromValue(it.value());
        d->ui.dockWidgetsComboBox->addItem(it.key(), vDockWidget);
    }
}

//============================================================================
StatusDialog::~StatusDialog()
{
    delete d;
}


//============================================================================
void StatusDialog::on_dockWidgetsComboBox_currentIndexChanged(int index)
{
    if (index < 0)
    {
        return;
    }

    auto vDockWidget = d->ui.dockWidgetsComboBox->currentData();
    auto DockWidget = vDockWidget.value<QAds::DockWidget*>();
    d->ui.isClosedCheckBox->setChecked(DockWidget->isClosed());
    d->ui.isFloatingCheckBox->setChecked(DockWidget->isFloating());
    d->ui.tabbedCheckBox->setChecked(DockWidget->isTabbed());
    d->ui.isCurrentTabCheckBox->setChecked(DockWidget->isCurrentTab());
    d->ui.closableCheckBox->setChecked(DockWidget->features().testFlag(QAds::DockWidget::DockWidgetClosable));
    d->ui.movableCheckBox->setChecked(DockWidget->features().testFlag(QAds::DockWidget::DockWidgetMovable));
    d->ui.floatableCheckBox->setChecked(DockWidget->features().testFlag(QAds::DockWidget::DockWidgetFloatable));
    d->ui.deleteOnCloseCheckBox->setChecked(DockWidget->features().testFlag(QAds::DockWidget::DockWidgetDeleteOnClose));
    d->ui.customCloseHandlingCheckBox->setChecked(DockWidget->features().testFlag(QAds::DockWidget::CustomCloseHandling));
}

